/*
 * @Author: 陈宇 975155172@qq.com
 * @Date: 2024-08-14 10:58:52
 * @LastEditors: 陈宇 975155172@qq.com
 * @LastEditTime: 2024-08-26 15:48:11
 * @FilePath: \blog-web\src\router\guard\userLoginInfo.ts
 * @Description: 根据权限判断是否展示
 */
import type { Router } from 'vue-router';
import NProgress from 'nprogress'; // progress bar

import { useUserStore } from '@/stores';

export default function setupUserLoginInfoGuard(router: Router) {
  router.beforeEach(async (to, from, next) => {
    NProgress.start();
    const userStore = useUserStore();
    // 判断是否获取过角色信息
    if (userStore.web_name) {
      next();
    } else {
      await userStore.info();
      next();
    }
  });
}
